package ${packageName}.controller;

import ${packageName}.pojo.${modelName};
import ${packageName}.service.${serviceName};
import ${packageName}.result.Pager;
import ${packageName}.result.Result;

<#if plugin.enableCustomAnnotation>
    import ${packageName}.common.Annotation;

</#if>
import java.util.List;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
<#if plugin.enableSwagger>
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
</#if>


/**
*${remarksTable}管理
*/
<#if plugin.enableCustomAnnotation>
    @Annotation(name = "${remarksTable}管理")

</#if>
<#if plugin.enableSwagger>
@Api(value = "/${modelName?uncap_first}", tags = {"${remarksTable}管理"})
</#if>
@RestController
@RequestMapping("/${modelName?uncap_first}")
public class ${controllerName}{

@Resource
private ${serviceName} ${serviceName?uncap_first};


/**
* 增加${remarksTable}数据
* @param record
* @return
* @throws Exception
*/
<#if plugin.enableCustomAnnotation>
    @Annotation(name = "增加${remarksTable}数据")

</#if>
<#if plugin.enableSwagger>
@ApiImplicitParams({
@ApiImplicitParam(paramType = "query", dataType = "${modelName}", name = "record", value = "")
})
@ApiOperation(value = "增加${remarksTable}数据", notes = "增加${remarksTable}数据", httpMethod = "POST")
</#if>
@PostMapping("/insert${modelName}")
public  Result insert${modelName}(${modelName} record)throws Exception{

return Result.insert( ${serviceName?uncap_first}.insert${modelName}(record));

}


<#if primaryKeyColumns ?has_content  && (primaryKeyColumns?size > 0)>
    /**
    * 删除${remarksTable}数据
    <#list primaryKeyColumns as column>
    * @param ${column.propertyName?uncap_first}</#list>
    * @return
    * @throws Exception
    */
<#if plugin.enableCustomAnnotation>
    @Annotation(name = "删除${remarksTable}数据")

    </#if>
    <#if plugin.enableSwagger>
        @ApiImplicitParams({
        <#list primaryKeyColumns as column>
            <#if column_index != 0> , </#if>
            @ApiImplicitParam(paramType = "query", dataType = "${column.javaType}", name = "${column.propertyName?uncap_first}", value = "")
        </#list>
        })
        @ApiOperation(value = "删除${remarksTable}数据", notes = "删除${remarksTable}数据", httpMethod = "POST")
    </#if>
    @PostMapping("/delete${modelName}ByPrimaryKey")
    public  Result delete${modelName}ByPrimaryKey(<#list primaryKeyColumns as column><#if column_index != 0> , </#if> ${column.javaType} ${column.propertyName?uncap_first} </#list>)throws Exception{
      return Result.delete(${serviceName?uncap_first}.delete${modelName}ByPrimaryKey(<#list primaryKeyColumns as column><#if column_index != 0> , </#if>  ${column.propertyName?uncap_first} </#list>));

    }
</#if>

<#if primaryKeyColumns ?has_content  && (primaryKeyColumns?size > 0)>
    /**
    * 通过主键删除多条${remarksTable}数据
    <#list primaryKeyColumns as column>
    * @param ${column.propertyName?uncap_first}s</#list>
    * @return
    * @throws Exception
    */
<#if plugin.enableCustomAnnotation>
    @Annotation(name = "通过主键删除多条${remarksTable}数据")

    </#if>
    <#if plugin.enableSwagger>
        @ApiImplicitParams({
        <#list primaryKeyColumns as column>
            <#if column_index != 0> , </#if>
            @ApiImplicitParam(paramType = "query", dataType = "String []", name = "${column.propertyName?uncap_first}s", value = "")
        </#list>
        })
        @ApiOperation(value = "通过主键删除多条${remarksTable}数据", notes = "通过主键删除多条${remarksTable}数据", httpMethod = "POST")
    </#if>
    @PostMapping("/delete${modelName}ByIds")
    public  Result delete${modelName}ByIds(<#list primaryKeyColumns as column><#if column_index != 0> , </#if> String [] ${column.propertyName?uncap_first}s</#list>)throws Exception{

    return Result.delete(${serviceName?uncap_first}.delete${modelName}ByIds(<#list primaryKeyColumns as column><#if column_index != 0> , </#if>  ${column.propertyName?uncap_first}s </#list>));



    }
</#if>


<#if primaryKeyColumns ?has_content  && (primaryKeyColumns?size > 0)>
    /**
    * 更新${remarksTable}数据
    * @param record
    * @return
    * @throws Exception
    */
<#if plugin.enableCustomAnnotation>
    @Annotation(name = "更新${remarksTable}数据")

    </#if>
    <#if plugin.enableSwagger>
        @ApiImplicitParams({
            @ApiImplicitParam(paramType = "query", dataType = "${modelName}", name = "record", value = "")
        })
        @ApiOperation(value = "更新${remarksTable}数据", notes = "更新${remarksTable}数据", httpMethod = "POST")
    </#if>
    @PostMapping("/update${modelName}ByPrimaryKey")
    public  Result update${modelName}ByPrimaryKey(${modelName} record)throws Exception{

    return Result.update(${serviceName?uncap_first}.update${modelName}ByPrimaryKey(record));
    }
</#if>
<#if primaryKeyColumns ?has_content  &&  (primaryKeyColumns?size > 0 && primaryKeyColumns?size == 1)>
    <#list primaryKeyColumns as column>
    /**
    * 批量更新属性不为空${remarksTable}数据
    * @param record
    * @return
    */
<#if plugin.enableCustomAnnotation>
    @Annotation(name = "更新属性不为空${remarksTable}数据")

    </#if>
<#if plugin.enableSwagger>
    @ApiImplicitParams({
    @ApiImplicitParam(paramType = "query", dataType = "${modelName} ", name = "record", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "String []", name = "${column.propertyName?uncap_first}s", value = "")
    })
    @ApiOperation(value = "批量更新属性不为空${remarksTable}数据", notes = "批量更新属性不为空${remarksTable}数据", httpMethod = "POST")

</#if>
    @PostMapping("/update${modelName}ByPrimaryKeyNotNull")

    public  Result update${modelName}ByPrimaryKeyNotNull(${modelName} record, String [] ${column.propertyName?uncap_first}s)throws Exception{

    return Result.update(${serviceName?uncap_first}.update${modelName}ByPrimaryKeyNotNull(record,${column.propertyName?uncap_first}s));

    }
    </#list>
</#if>

<#if primaryKeyColumns ?has_content  && (primaryKeyColumns?size > 0)>
    /**
    * 通过主键查询${remarksTable}数据
    <#list primaryKeyColumns as column>
    * @param ${column.propertyName?uncap_first}</#list>
    * @return
    */
<#if plugin.enableCustomAnnotation>
    @Annotation(name = "通过主键查询${remarksTable}数据")
    </#if>
<#if plugin.enableSwagger>
    @ApiImplicitParams({
    <#list primaryKeyColumns as column>
        <#if column_index != 0> , </#if>
        @ApiImplicitParam(paramType = "query", dataType = "${column.javaType}", name = "${column.propertyName?uncap_first}", value = "")
    </#list>
     })
    @ApiOperation(value = "通过主键查询${remarksTable}数据", notes = "通过主键查询${remarksTable}数据", httpMethod = "POST")
</#if>
    @PostMapping("/select${modelName}ByPrimaryKey")
    public  Result<${modelName}> select${modelName}ByPrimaryKey(<#list primaryKeyColumns as column> <#if column_index != 0> , </#if> ${column.javaType} ${column.propertyName?uncap_first} </#list>){

    return  Result.succeed(${serviceName?uncap_first}.select${modelName}ByPrimaryKey(<#list primaryKeyColumns as column><#if column_index != 0> , </#if>  ${column.propertyName?uncap_first} </#list>));

    }
</#if>


/**
* 通过条件查询${remarksTable}数据
* @param ${modelName?uncap_first}
* @param desc
* @param startTime 开始时间
* @param endTime 结束时间
* @param notNullAttributes 不为空筛选  多个,分割
* @param isNullAttributes 为空筛选 多个
* @param globalSearch
* @param likeNameSearch 全局模糊查询 格式 {字段:'条件'}
* @param amountSearch  数值金额全局查询
* @param universalTime    范围查询 格式 {字段:{startTime:'',endTime:''}}
* @param multipleChoiceCondition 多选条件     格式 {字段:[数据,数据]}
* @param fieldConditionStr 高级查询json 格式[{databaseId:'',relationId:'',datas:[]}]
* @return
*/
<#if plugin.enableCustomAnnotation>
@Annotation(name = "通过条件查询${remarksTable}数据")
</#if>
<#if plugin.enableSwagger>
    @ApiImplicitParams({
    @ApiImplicitParam(paramType = "query", dataType = "${modelName}", name = "${modelName?uncap_first}", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "desc", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "startTime", value = "开始时间"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "endTime", value = "结束时间"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "notNullAttributes", value = "不为空筛选 多个,分割"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "isNullAttributes", value = "为空筛选 多个"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "globalSearch", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "likeNameSearch", value = "全局模糊查询 格式 {字段:'条件'}"),
    @ApiImplicitParam(paramType = "query", dataType = "double", name = "amountSearch", value = "数值金额全局查询"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "universalTime", value = "范围查询 格式 {字段:{startTime:'',endTime:''}}"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "multipleChoiceCondition", value = "多选条件 格式 {字段:[数据,数据]}"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "fieldConditionStr", value = "高级查询json 格式[{databaseId:'',relationId:'',datas:[]}]")
    })
    @ApiOperation(value = "通过条件查询${remarksTable}数据", notes = "通过条件查询${remarksTable}数据", httpMethod = "POST")
</#if>
@PostMapping("/select${modelName}")
public Result<${modelName}> select${modelName}(${modelName} ${modelName?uncap_first}, String desc, String startTime, String endTime, String notNullAttributes,
String isNullAttributes, String globalSearch,String likeNameSearch, Double amountSearch, String universalTime,String multipleChoiceCondition, String fieldConditionStr){

return Result.succeed(${serviceName?uncap_first}.select${modelName}(${modelName?uncap_first},  desc,  startTime,
endTime,  notNullAttributes,
isNullAttributes,  globalSearch, likeNameSearch,  amountSearch,universalTime,multipleChoiceCondition,fieldConditionStr));

}


/**
* 总条数
* @param ${modelName?uncap_first}
* @param desc
* @param startTime 开始时间
* @param endTime 结束时间
* @param notNullAttributes 不为空筛选  多个,分割
* @param isNullAttributes 为空筛选 多个
* @param globalSearch
* @param likeNameSearch
* @param amountSearch
* @param universalTime    时间 格式 {字段:{startTime:'',endTime:''}}
* @param multipleChoiceCondition 多选条件     格式 {字段:[数据,数据]}
* @return
*/
<#if plugin.enableSwagger>
    @ApiImplicitParams({
    @ApiImplicitParam(paramType = "query", dataType = "${modelName}", name = "${modelName?uncap_first}", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "desc", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "startTime", value = "开始时间"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "endTime", value = "结束时间"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "notNullAttributes", value = "不为空筛选 多个,分割"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "isNullAttributes", value = "为空筛选 多个"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "globalSearch", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "likeNameSearch", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "double", name = "amountSearch", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "universalTime", value = "时间 格式 {字段:{startTime:'',endTime:''}}"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "multipleChoiceCondition", value = "多选条件 格式 {字段:[数据,数据]}"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "fieldConditionStr", value = "")
    })
    @ApiOperation(value = "总条数", notes = "总条数", httpMethod = "POST")
</#if>
@PostMapping("/get${modelName}PageCount")
public Result get${modelName}PageCount(${modelName} ${modelName?uncap_first}, String desc, String startTime,
String endTime, String notNullAttributes,
String isNullAttributes, String globalSearch,String likeNameSearch, Double amountSearch, String universalTime,String multipleChoiceCondition, String fieldConditionStr){
return Result.succeed( ${serviceName?uncap_first}.get${modelName}PageCount(${modelName?uncap_first},  desc,  startTime,
 endTime,  notNullAttributes,
 isNullAttributes,  globalSearch, likeNameSearch,  amountSearch,universalTime,multipleChoiceCondition,fieldConditionStr));



}
/**
* 分页获取${remarksTable}
* @param page 当前页
* @param limit 每页显示数
* @param initSort 以什么排序
* @param desc 是否降序排序
* @param ${modelName?uncap_first}
* @param startTime 开始时间
* @param endTime 结束时间
* @param notNullAttributes 不为空筛选  多个,分割
* @param isNullAttributes 为空筛选 多个
* @param globalSearch 全局搜素
* @param likeNameSearch 模糊查询 格式 {字段:'条件'}
* @param amountSearch 数值模糊查询
* @param universalTime    时间 格式 {字段:{startTime:'',endTime:''}}
* @param multipleChoiceCondition 多选条件格式 {字段:[数据,数据]}
* @param fieldConditionStr 高级查询json 格式[{databaseId:'',relationId:'',datas:[]}]
* @param isLimit 是否分页  默认true true/false
* @return
*/
<#if plugin.enableCustomAnnotation>
@Annotation(name = "分页获取${remarksTable}")
</#if>
<#if plugin.enableSwagger>
    @ApiImplicitParams({
    @ApiImplicitParam(paramType = "query", dataType = "long", name = "page", value = "当前页"),
    @ApiImplicitParam(paramType = "query", dataType = "int", name = "limit", value = "每页显示数"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "initSort", value = "以什么排序"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "desc", value = "是否降序排序"),
    @ApiImplicitParam(paramType = "query", dataType = "${modelName}", name = "${modelName?uncap_first}", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "startTime", value = "开始时间"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "endTime", value = "结束时间"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "notNullAttributes", value = "不为空筛选 多个,分割"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "isNullAttributes", value = "为空筛选 多个"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "globalSearch", value = ""),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "likeNameSearch", value = "模糊查询 格式 {字段:'条件'}"),
    @ApiImplicitParam(paramType = "query", dataType = "double", name = "amountSearch", value = "数值模糊查询"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "universalTime", value = "时间 格式 {字段:{startTime:'',endTime:''}}"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "multipleChoiceCondition", value = "多选条件 格式 {字段:[数据,数据]}"),
    @ApiImplicitParam(paramType = "query", dataType = "string", name = "fieldConditionStr", value = "高级查询json 格式[{databaseId:'',relationId:'',datas:[]}]")
    })
    @ApiOperation(value = "分页获取${remarksTable}", notes = "分页获取${remarksTable}", httpMethod = "POST")
</#if>
@PostMapping("/get${modelName}Page")
public Pager<${modelName}> get${modelName}Page(@RequestParam(value = "page", required = false, defaultValue = "0") long page, @RequestParam(value = "limit", required = false, defaultValue = "10") int limit, String initSort, String desc, ${modelName} ${modelName?uncap_first},
String startTime, String endTime, String notNullAttributes, String isNullAttributes, String globalSearch, String likeNameSearch,
Double amountSearch, String universalTime,String multipleChoiceCondition, String fieldConditionStr ,String isLimit){

return ${serviceName?uncap_first}.get${modelName}Page(page, limit, initSort, ${modelName?uncap_first}, desc, startTime, endTime, notNullAttributes, isNullAttributes, globalSearch,likeNameSearch,amountSearch,universalTime,multipleChoiceCondition,fieldConditionStr,isLimit);

}



<#--@GetMapping("/${modelName?lower_case}s")
public List<${modelName}> getAll${modelName}s(){
return ${serviceName?uncap_first}.getAll${modelName}s();
}-->
}